package com.ruoyi.environment.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.environment.domain.OpmEnvRule;
import com.ruoyi.environment.domain.OpmEnvSewageTest;
import com.ruoyi.environment.mapper.OpmEnvSewageTestMapper;
import com.ruoyi.environment.service.IOpmEnvSewageTestService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 污水采集Service业务层处理
 *
 * @author cjie
 * @date 2021-07-23
 */
@Service
public class OpmEnvSewageTestServiceImpl extends LinkFileServiceImpl implements IOpmEnvSewageTestService {
    @Autowired
    private OpmEnvSewageTestMapper opmEnvSewageTestMapper;

    /**
     * 查询污水采集
     *
     * @param id 污水采集ID
     * @return 污水采集
     */
    @Override
    public OpmEnvSewageTest selectOpmEnvSewageTestById(Long id) {
        OpmEnvSewageTest result = opmEnvSewageTestMapper.selectOpmEnvSewageTestById(id);
        result.setFileList(getFileList(id.toString()));
        return result;
    }

    /**
     * 查询污水采集列表
     *
     * @param opmEnvSewageTest 污水采集
     * @return 污水采集
     */
    @Override
    public List<OpmEnvSewageTest> selectOpmEnvSewageTestList(OpmEnvSewageTest opmEnvSewageTest) {
        return opmEnvSewageTestMapper.selectOpmEnvSewageTestList(opmEnvSewageTest);
    }

    /**
     * 新增污水采集
     *
     * @param opmEnvSewageTest 污水采集
     * @return 结果
     */
    @Override
    public int insertOpmEnvSewageTest(OpmEnvSewageTest opmEnvSewageTest) {
        opmEnvSewageTest.setId(IdUtil.getSnowflake(0, 0).nextId());
        opmEnvSewageTest.setCreateTime(DateUtils.getNowDate());
        opmEnvSewageTest.setCreateBy(SecurityUtils.getUsername());
        linkFile(opmEnvSewageTest.getFileIdList(), opmEnvSewageTest.getId().toString());
        return opmEnvSewageTestMapper.insertOpmEnvSewageTest(opmEnvSewageTest);
    }

    /**
     * 修改污水采集
     *
     * @param opmEnvSewageTest 污水采集
     * @return 结果
     */
    @Override
    public int updateOpmEnvSewageTest(OpmEnvSewageTest opmEnvSewageTest) {
        opmEnvSewageTest.setUpdateTime(DateUtils.getNowDate());
        opmEnvSewageTest.setUpdateBy(SecurityUtils.getUsername());
        linkFile(opmEnvSewageTest.getFileIdList(),Long.toString(opmEnvSewageTest.getId()));
        return opmEnvSewageTestMapper.updateOpmEnvSewageTest(opmEnvSewageTest);
    }

    /**
     * 批量删除污水采集
     *
     * @param ids 需要删除的污水采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvSewageTestByIds(Long[] ids) {

        String[] res = new String[ids.length];
        for(int i=0;i<ids.length;i++){
            res[i] = String.valueOf(ids[i]);
        }
        deleteLinkFile(res);
        return opmEnvSewageTestMapper.deleteOpmEnvSewageTestByIds(ids);
    }

    /**
     * 删除污水采集信息
     *
     * @param id 污水采集ID
     * @return 结果
     */
    @Override
    public int deleteOpmEnvSewageTestById(Long id) {
        return opmEnvSewageTestMapper.deleteOpmEnvSewageTestById(id);
    }
}
